package com.ejuornal.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import com.ejuornal.bean.Board;
import com.ejuornal.bean.Page;
import com.ejuornal.dao.BoardDao;
import com.ejuornal.service.BoardService;
@Component("boardService")
public class BoardServiceImpl implements BoardService {
	private BoardDao boardDao;
	
	public void add(Board board) {
		String sql = "INSERT INTO t_board VALUES(?, ?, ?)";
		boardDao.add(sql, new Object[]{
						null,
						board.getName(), 
						board.getPeriodicalId() });
	}

	public void update(Board board) {
		String sql = "UPDATE t_board SET name=?, periodicalId=? WHERE boardId=?";
		boardDao.update(sql, new Object[]{ 
				board.getName(),
				board.getPeriodicalId(),
				board.getBoardId()
		});
	}

	public void delete(int... boardIds) {
		String sql = "DELETE t_board WHERE boardId=?";
		boardDao.batchDelete(sql, boardIds);
	}

	public List<Board> findByPeriodicalId(int periodicalId) {
		return boardDao.findByPeriodicalId(periodicalId);
	}

	public Page<Board> find(int current_record, String url) {
		return boardDao.find(current_record, url);
	}

	public BoardDao getBoardDao() {
		return boardDao;
	}
	@Resource(name="boardDao")
	public void setBoardDao(BoardDao boardDao) {
		this.boardDao = boardDao;
	}

}
